$(function() {
	$('#vue_vm_list div').hide();
});

var mealCard = {
	mealCardId: '',
	cardPersonId: '',
	cardPersonName: '',
	cardCardId: '',
	walletBalance: '',
	cardType: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	userRfidCardId: '',
};

var view = {
	data: mealCard
};

function recharge() {
	var cardPersonId = $('#cardPersonId').val();
	var payWay = parseInt($('input:radio[name="payWay"]:checked').val());
	//var money = parseFloat($('#money').val());
	var pracMoney = parseFloat($('#pracMoney').val());
	var preBalance = parseFloat($('#preBalance').val());
	preBalance = (preBalance==''? 0: preBalance);
	
	if(isEmpty(cardPersonId)) {
		alert('请选择饭卡');
		return;
	}
	
	if(isEmpty(payWay) || payWay==0) {
		alert('请选择充值方式');
		return;
	}
	
	/*
	if(isEmpty(money) || money==0) {
		alert('请输入充值金额');
		return;
	}
	*/
	
	if(isEmpty(pracMoney) || pracMoney==0) {
		alert('请输入实收金额');
		return;
	}
	
	if(isEmpty(preBalance)) {
		preBalance = 0;
	}
	
	if(confirm('确定充值' + pracMoney + '元，赠送' + preBalance + '元吗？')) {
		save_basic_by_json(path+'/mealCard/recharge', {cardPersonId:cardPersonId, pracMoney:pracMoney, preBalance:preBalance,
		payType:payWay, updateId:view.data.updateId, createId:view.data.createId}, function(response) {
			alert('充值成功');
			var pageParam = {};
			pageParam.mealCardRechargeRecordId = response.data[0].mealCardRechargeRecordId;
			pageParam.cardPersonName = response.data[0].cardPersonName
			pageParam.cardCardId = response.data[0].cardCardId;
			pageParam.payWay = payWay;
			pageParam.rechargeMoney = response.data[0].rechargeMoney;
			pageParam.pracRechargeMoney = response.data[0].pracRechargeMoney;
			pageParam.preBalance = preBalance;
			pageParam.mealCardBalance = response.data[0].mealCardBalance;
			pageParam.mealCardPreBalance = response.data[0].mealCardPreBalance;
			pageParam.handler = response.data[0].handler;
			pageParam.rechargeDate = response.data[0].rechargeDate;
			//document.location.href = '9-2-2fangkaadd-1.html?pageParam='+encodeURIComponent(JSON.stringify(pageParam));
		});
	}
}

function deleteBatch() {
	deleteBatch_basic(path+'/mealCard/deleteBatch');
}

var autoSearchDetail = function(searchVal) {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();
	
	openWaiting('正在查找');
	
	find_basic(path+'/mealCard/find', searchVal, function(response) {
		closeWaiting();
		
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			}
		});
		
		$('#vue_vm_list div').show();
	});
}
